package org.mihalovic.PES.Core.Graph;

import java.util.Comparator;



/**
 * Comparator used to compare two <code>Nodes</code> depending on their rank score.
 * <br/><br/>
 * Note: the <code>compare</code> method never returns 0. Instead, it returns 1 for 'equal'
 * <code>Node</code> objects. It's because it is meant to be used as comparator for <code>SortedSet</code>
 * instances, but it's inconsistency with <code>equals</code> causes really 'strange'
 * behavior (<code>sortedSet.add(node)</code> fails if <code>sortedSet.contains(n2) && compare(node, n2)==0</code>
 * even if <code>node.equals(n2)==false</code>).
 * 
 * @author Martin Mihalovic
 */
public class RankBasedNodeComparator implements Comparator<Node> {
    public int compare(Node n1, Node n2) {
        if(n1.getRank().DoubleValue() == n2.getRank().DoubleValue())
            return /*0*/1;         //Ugh!
        if(n1.getRank().DoubleValue() > n2.getRank().DoubleValue())
            return 1;
        return -1;
    }
}
